<%@ taglib prefix="c" uri="http://java.sun.com/jsp/jstl/core" %>
<%@ taglib prefix="fmt" uri="http://java.sun.com/jsp/jstl/fmt" %>
<%--
  Created by IntelliJ IDEA.
  User: Z-7
  Date: 2022/3/22
  Time: 14:18
  To change this template use File | Settings | File Templates.
--%>
<%@ page contentType="text/html;charset=UTF-8" language="java" %>
<html>
<head>
    <meta charset="utf-8">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <link href="/bootstrap4/css/bootstrap.css" rel="stylesheet">
    <title>枪械列表</title>
</head>
<body>
<script type="text/javascript" src="/js/jquery-3.2.1.js"></script>
<script type="text/javascript" src="/bootstrap-treeview/js/bootstrap-treeview.js"></script>
<script src="/bootstrap4/js/bootstrap.js"></script>
<blockquote class="blockquote text-center">
    <p class="mb-0">欧美军火商</p>
    <footer class="blockquote-footer">俄罗斯<cite title="Source Title">军火库</cite></footer>
</blockquote>

<div class="container">
    <form action="/firearms/esList" method="post">
        <input type="hidden" name="pageNum" value="${page.pageNum}">
        <input type="text" name="search" placeholder="枪械名称或者配件" value="${search}">
        <button type="submit" class="btn btn-outline-dark">搜索</button>
    </form>
    <table class="table table-hover">
        <thead>
        <tr>
            <th scope="col">枪械编号</th>
            <th scope="col">名称</th>
            <th scope="col">弹容量</th>
            <th scope="col">类型</th>
            <th scope="col">子弹型号</th>
            <th scope="col">发布日期</th>
            <th scope="col">配件</th>
            <th scope="col">皮肤展示</th>
            <th scope="col">操作</th>
        </tr>
        </thead>
        <tbody>
        <c:forEach items="${page.list}" var="fire">
            <tr>
                <th scope="row">${fire.id}</th>
                <td>${fire.name}</td>
                <td>${fire.capacity}</td>
                <td>${fire.typeName}</td>
                <td>${fire.model}</td>
                <td>
                    <fmt:formatDate value="${fire.publishDate}" pattern="yyyy-MM-dd"/>
                </td>
                <td>${fire.partsName}</td>
                <td>
                    <img src="${fire.skin}" height="80px" width="80px">
                </td>
                <td>
                    <button type="button" class="btn btn-primary" onclick="to_update(${fire.id})">修改</button>
                    <button type="button" class="btn btn-secondary" onclick="to_del(${fire.id})">删除</button>
                </td>
            </tr>
        </c:forEach>
        <tr>
            <td colspan="100">
                <button type="button" onclick="goPage(1)" class="btn btn-outline-primary">首页</button>
                <button type="button" onclick="goPage(${page.pageNum == 1 ? 1 : page.pageNum - 1})" class="btn btn-outline-primary">上一页</button>
                <button type="button" onclick="goPage(${page.pageNum == page.pages ? page.pages : page.pageNum + 1})" class="btn btn-outline-primary">下一页</button>
                <button type="button" onclick="goPage(${page.pages})" class="btn btn-outline-primary">尾页</button>
                <button type="button" class="btn btn-outline-dark" onclick="to_add()">新增</button>
            </td>
        </tr>
        </tbody>
    </table>
</div>
<script type="text/javascript">
    function goPage(pageNum) {
        $('[name="pageNum"]').val(pageNum);
        $("form").submit();
    }
    function to_add() {
        location="/firearms/to_add";
    }
    function to_update(id) {
        location="/firearms/to_update?id="+id;
    }
    function to_del(id) {
        $.post("/firearms/del",{id:id},function (obj) {
            if(obj.result){
                alert("删除成功");
                location.reload();
            }else {
                alert(obj.msg);
            }
        })
    }
</script>
</body>
</html>
